/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project.jpdftools.ui.actionlisteners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import project.jpdftools.managers.LoggerManager;
import project.jpdftools.toolkit.Toolkit;
import project.jpdftools.ui.MainMenu;
import project.jpdftools.managers.other.FileUtil;

/**
 *
 * @author Mido
 */
public class ApplyThemeAction implements ActionListener {

    private String theme_name;  // theme string that will be used to create an object of the theme

    /**
     * Constructor with parameters
     *
     * @param theme_name theme string that will be used to create an object of
     * the theme
     */
    public ApplyThemeAction(String theme_name) {
        this.theme_name = theme_name;
    }

    /**
     * The action that will be performed by this action listener
     *
     * @param evt
     */
    public void actionPerformed(ActionEvent evt) {
        try {
            UIManager.setLookAndFeel(theme_name);
            // MainMenu has been initialized, then we can apply the look and feel
            SwingUtilities.updateComponentTreeUI(MainMenu.getInstance());
        } catch (Exception e) {
            LoggerManager.getLogger().log(Level.SEVERE, "An excption occurred. {0}", Toolkit.getStackTraceAsString(e.getCause()));
        }

        // write in the file to use this theme in next sessions
        new FileUtil().writeToFile("Data/Theme.txt", theme_name, false, false);
        LoggerManager.getLogger().log(Level.INFO, "Theme changed to \"{0}\"", theme_name);
    }
}
